namespace DB_EntityFramework.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class MyCoolMigration : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Educations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Resume_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Resumes", t => t.Resume_Id)
                .Index(t => t.Resume_Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Login = c.String(nullable: false, maxLength: 50),
                        Password = c.String(nullable: false),
                        Email = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.Login, unique: true);
            
            CreateTable(
                "dbo.Sities",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Resume_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Resumes", t => t.Resume_Id)
                .Index(t => t.Resume_Id);
            
            CreateTable(
                "dbo.Roles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Vacancies",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Salary = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Demands = c.String(nullable: false),
                        Job_Description = c.String(nullable: false),
                        CurrentEmployer_Id = c.Int(),
                        Section_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Employer", t => t.CurrentEmployer_Id)
                .ForeignKey("dbo.WorkOnSections", t => t.Section_Id)
                .Index(t => t.CurrentEmployer_Id)
                .Index(t => t.Section_Id);
            
            CreateTable(
                "dbo.WorkOnSections",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserLanguages",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Vacancy_Id = c.Int(),
                        Resume_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Vacancies", t => t.Vacancy_Id)
                .ForeignKey("dbo.Resumes", t => t.Resume_Id)
                .Index(t => t.Vacancy_Id)
                .Index(t => t.Resume_Id);
            
            CreateTable(
                "dbo.Languages",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        UserLanguage_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.UserLanguages", t => t.UserLanguage_Id)
                .Index(t => t.UserLanguage_Id);
            
            CreateTable(
                "dbo.LevelLanguages",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        UserLanguage_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.UserLanguages", t => t.UserLanguage_Id)
                .Index(t => t.UserLanguage_Id);
            
            CreateTable(
                "dbo.Resumes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Target = c.String(nullable: false),
                        Work_Experience = c.String(nullable: false),
                        Additional_Information = c.String(nullable: false),
                        Work_on_SectionsID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserRoles",
                c => new
                    {
                        User_Id = c.Int(nullable: false),
                        Roles_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.User_Id, t.Roles_Id })
                .ForeignKey("dbo.Users", t => t.User_Id, cascadeDelete: true)
                .ForeignKey("dbo.Roles", t => t.Roles_Id, cascadeDelete: true)
                .Index(t => t.User_Id)
                .Index(t => t.Roles_Id);
            
            CreateTable(
                "dbo.Employee",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        City_Id = c.Int(),
                        Name = c.String(nullable: false),
                        LastName = c.String(nullable: false),
                        BirthDay = c.DateTime(nullable: false),
                        Phone = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.Id)
                .ForeignKey("dbo.Sities", t => t.City_Id)
                .Index(t => t.Id)
                .Index(t => t.City_Id);
            
            CreateTable(
                "dbo.Employer",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        Name = c.String(nullable: false),
                        Salary = c.Int(nullable: false),
                        CityID = c.Int(nullable: false),
                        ContactID = c.Int(nullable: false),
                        Address = c.String(nullable: false),
                        Phone = c.String(nullable: false),
                        Skype = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.Id)
                .Index(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Employer", "Id", "dbo.Users");
            DropForeignKey("dbo.Employee", "City_Id", "dbo.Sities");
            DropForeignKey("dbo.Employee", "Id", "dbo.Users");
            DropForeignKey("dbo.UserLanguages", "Resume_Id", "dbo.Resumes");
            DropForeignKey("dbo.Sities", "Resume_Id", "dbo.Resumes");
            DropForeignKey("dbo.Educations", "Resume_Id", "dbo.Resumes");
            DropForeignKey("dbo.UserLanguages", "Vacancy_Id", "dbo.Vacancies");
            DropForeignKey("dbo.LevelLanguages", "UserLanguage_Id", "dbo.UserLanguages");
            DropForeignKey("dbo.Languages", "UserLanguage_Id", "dbo.UserLanguages");
            DropForeignKey("dbo.Vacancies", "Section_Id", "dbo.WorkOnSections");
            DropForeignKey("dbo.Vacancies", "CurrentEmployer_Id", "dbo.Employer");
            DropForeignKey("dbo.UserRoles", "Roles_Id", "dbo.Roles");
            DropForeignKey("dbo.UserRoles", "User_Id", "dbo.Users");
            DropIndex("dbo.Employer", new[] { "Id" });
            DropIndex("dbo.Employee", new[] { "City_Id" });
            DropIndex("dbo.Employee", new[] { "Id" });
            DropIndex("dbo.UserRoles", new[] { "Roles_Id" });
            DropIndex("dbo.UserRoles", new[] { "User_Id" });
            DropIndex("dbo.LevelLanguages", new[] { "UserLanguage_Id" });
            DropIndex("dbo.Languages", new[] { "UserLanguage_Id" });
            DropIndex("dbo.UserLanguages", new[] { "Resume_Id" });
            DropIndex("dbo.UserLanguages", new[] { "Vacancy_Id" });
            DropIndex("dbo.Vacancies", new[] { "Section_Id" });
            DropIndex("dbo.Vacancies", new[] { "CurrentEmployer_Id" });
            DropIndex("dbo.Sities", new[] { "Resume_Id" });
            DropIndex("dbo.Users", new[] { "Login" });
            DropIndex("dbo.Educations", new[] { "Resume_Id" });
            DropTable("dbo.Employer");
            DropTable("dbo.Employee");
            DropTable("dbo.UserRoles");
            DropTable("dbo.Resumes");
            DropTable("dbo.LevelLanguages");
            DropTable("dbo.Languages");
            DropTable("dbo.UserLanguages");
            DropTable("dbo.WorkOnSections");
            DropTable("dbo.Vacancies");
            DropTable("dbo.Roles");
            DropTable("dbo.Sities");
            DropTable("dbo.Users");
            DropTable("dbo.Educations");
        }
    }
}
